package com.tutu.book.controller;


import com.tutu.book.service.BookService;
import com.tutu.commons.entity.Book;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Program: SpringCloud
 * @Description:
 * @Author: JK.TuTu
 * @Version: 1.0
 * @Create: 2022-12-01 13:08
 **/
@RestController
@RequestMapping("/book")
public class BookController {

    @Resource
    BookService service;

    @GetMapping("/{bid}")
    Book findBookById(@PathVariable("bid") int bid){
        return service.getBookById(bid);
    }

    /**
     * 根据bid获取图书数量
     */
    @GetMapping("/getBookNum/{bid}")
    public int getBookNum(@PathVariable("bid") int bid){
        return service.getBookNum(bid);
    }

    @GetMapping("/bookBorrow/{bid}")
    public boolean bookBorrow(@PathVariable("bid") int bid){
        int num=service.getBookNum(bid);
        return service.bookBorrow(bid,num-1)>1;

    }
}